<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-telescope" tabindex="-1"><a class="header-anchor" href="#laravel-telescope"><span>Laravel Telescope</span></a></h2>
<ul>
<li><a href="#introduction">介绍</a></li>
<li><a href="#installation">安装</a>
<ul>
<li><a href="#local-only-installation">仅本地安装</a></li>
<li><a href="#configuration">配置</a></li>
<li><a href="#data-pruning">数据修剪</a></li>
<li><a href="#dashboard-authorization">仪表板授权</a></li>
</ul>
</li>
<li><a href="#upgrading-telescope">升级 Telescope</a></li>
<li><a href="#filtering">过滤</a>
<ul>
<li><a href="#filtering-entries">条目</a></li>
<li><a href="#filtering-batches">批次</a></li>
</ul>
</li>
<li><a href="#tagging">标记</a></li>
<li><a href="#available-watchers">可用观察者</a>
<ul>
<li><a href="#batch-watcher">批次观察者</a></li>
<li><a href="#cache-watcher">缓存观察者</a></li>
<li><a href="#command-watcher">命令观察者</a></li>
<li><a href="#dump-watcher">转储观察者</a></li>
<li><a href="#event-watcher">事件观察者</a></li>
<li><a href="#exception-watcher">异常观察者</a></li>
<li><a href="#gate-watcher">门禁观察者</a></li>
<li><a href="#http-client-watcher">HTTP 客户端观察者</a></li>
<li><a href="#job-watcher">作业观察者</a></li>
<li><a href="#log-watcher">日志观察者</a></li>
<li><a href="#mail-watcher">邮件观察者</a></li>
<li><a href="#model-watcher">模型观察者</a></li>
<li><a href="#notification-watcher">通知观察者</a></li>
<li><a href="#query-watcher">查询观察者</a></li>
<li><a href="#redis-watcher">Redis 观察者</a></li>
<li><a href="#request-watcher">请求观察者</a></li>
<li><a href="#schedule-watcher">计划观察者</a></li>
<li><a href="#view-watcher">视图观察者</a></li>
</ul>
</li>
<li><a href="#displaying-user-avatars">显示用户头像</a></li>
</ul>
<h2 id="介绍" tabindex="-1"><a class="header-anchor" href="#介绍"><span>介绍</span></a></h2>
<p><a href="https://github.com/laravel/telescope" target="_blank" rel="noopener noreferrer">Laravel Telescope</a> 是你本地 Laravel 开发环境的绝佳伴侣。Telescope 可以为你的应用程序提供请求、异常、日志条目、数据库查询、队列作业、邮件、通知、缓存操作、定时任务、变量转储等方面的洞察。</p>
<p><img src="https://laravel.com/img/docs/telescope-example.png" alt="telescope-example.png"></p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>你可以使用 Composer 包管理器将 Telescope 安装到你的 Laravel 项目中：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/telescope</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装了 Telescope 后，使用 <code v-pre>telescope:install</code> Artisan 命令发布其资产和迁移。安装了 Telescope 后，你还应该运行 <code v-pre>migrate</code> 命令以创建存储 Telescope 数据所需的表：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan telescope:install</span>
<span class="line"></span>
<span class="line">php artisan migrate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最后，你可以通过 <code v-pre>/telescope</code> 路由访问 Telescope 仪表板。</p>
<h3 id="仅本地安装" tabindex="-1"><a class="header-anchor" href="#仅本地安装"><span>仅本地安装</span></a></h3>
<p>如果你计划仅在本地开发中使用 Telescope，可以使用 <code v-pre>--dev</code> 标志安装 Telescope：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/telescope <span class="token parameter variable">--dev</span></span>
<span class="line"></span>
<span class="line">php artisan telescope:install</span>
<span class="line"></span>
<span class="line">php artisan migrate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>运行完 <code v-pre>telescope:install</code> 后，应该从你的应用程序的 <code v-pre>bootstrap/providers.php</code> 配置文件中移除 <code v-pre>TelescopeServiceProvider</code> 服务提供程序的注册。相反，在 <code v-pre>App\Providers\AppServiceProvider</code> 类的 <code v-pre>register</code> 方法中手动注册 Telescope 的服务提供程序。我们将确保当前环境为 <code v-pre>local</code>，然后再注册这些提供程序：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>TelescopeServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name static-context">TelescopeServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最后，你还应该防止 Telescope 包被 <a href="https://learnku.com/docs/laravel/11.x/packages#package-discovery" target="_blank" rel="noopener noreferrer">自动发现</a> ，方法是在你的 <code v-pre>composer.json</code> 文件中添加以下内容：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token property">"extra"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"laravel"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"dont-discover"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"laravel/telescope"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="配置" tabindex="-1"><a class="header-anchor" href="#配置"><span>配置</span></a></h3>
<p>在发布 Telescope 的资产后，其主要配置文件将位于 <code v-pre>config/telescope.php</code>。这个配置文件允许你配置你的<a href="#available-watchers">观察者选项</a>。每个配置选项都包括其用途的描述，所以一定要彻底探索这个文件。</p>
<p>如果需要，你可以使用 <code v-pre>enabled</code> 配置选项完全禁用 Telescope 的数据收集：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_ENABLED'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="数据修剪" tabindex="-1"><a class="header-anchor" href="#数据修剪"><span>数据修剪</span></a></h3>
<p>如果不进行修剪，<code v-pre>telescope_entries</code> 表会很快积累记录。为了缓解这个问题，你应该 <a href="https://learnku.com/docs/laravel/11.x/scheduling" target="_blank" rel="noopener noreferrer">调度</a> <code v-pre>telescope:prune</code> Artisan 命令以每天运行：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Schedule</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Schedule</span><span class="token operator">::</span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>默认情况下，所有超过 24 小时的条目将被修剪。在调用命令时，你可以使用 <code v-pre>hours</code> 选项来确定保留 Telescope 数据的时间长度。例如，以下命令将删除 48 小时前创建的所有记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Schedule</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Schedule</span><span class="token operator">::</span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune --hours=48'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="仪表板授权" tabindex="-1"><a class="header-anchor" href="#仪表板授权"><span>仪表板授权</span></a></h3>
<p>Telescope 仪表板可以通过 <code v-pre>/telescope</code> 路由访问。默认情况下，你只能在 <code v-pre>local</code> 环境中访问此仪表板。在你的 <code v-pre>app/Providers/TelescopeServiceProvider.php</code> 文件中，有一个<a href="https://learnku.com/docs/laravel/11.x/authorization#gates" target="_blank" rel="noopener noreferrer">授权门</a>定义。这个授权门控制在<strong>非本地</strong>环境中访问 Telescope。你可以根据需要修改此门以限制对 Telescope 的访问：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register the Telescope gate.</span>
<span class="line"> *</span>
<span class="line"> * This gate determines who can access Telescope in non-local environments.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">gate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Gate</span><span class="token operator">::</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'viewTelescope'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">User</span> <span class="token variable">$user</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">in_array</span><span class="token punctuation">(</span><span class="token variable">$user</span><span class="token operator">-></span><span class="token property">email</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'taylor@laravel.com'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>[!WARNING]<br>
你应确保在生产环境中将你的 <code v-pre>APP_ENV</code> 环境变量更改为 <code v-pre>production</code>。否则，你的 Telescope 安装将公开可访问。</p>
</blockquote>
<h2 id="升级-telescope" tabindex="-1"><a class="header-anchor" href="#升级-telescope"><span>升级 Telescope</span></a></h2>
<p>当升级到 Telescope 的新主要版本时，重要的是仔细阅读<a href="https://github.com/laravel/telescope/blob/master/UPGRADE.md" target="_blank" rel="noopener noreferrer">升级指南</a>。</p>
<p>此外，当升级到任何新的 Telescope 版本时，你应该重新发布 Telescope 的资产：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan telescope:publish</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>为了保持资产的最新状态并避免未来更新中的问题，你可以将 <code v-pre>vendor:publish --tag=laravel-assets</code> 命令添加到你的应用程序的 <code v-pre>composer.json</code> 文件中的 <code v-pre>post-update-cmd</code> 脚本中：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"post-update-cmd"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"@php artisan vendor:publish --tag=laravel-assets --ansi --force"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="过滤" tabindex="-1"><a class="header-anchor" href="#过滤"><span>过滤</span></a></h2>
<h3 id="条目" tabindex="-1"><a class="header-anchor" href="#条目"><span>条目</span></a></h3>
<p>你可以通过在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类中定义的 <code v-pre>filter</code> 闭包来过滤 Telescope 记录的数据。默认情况下，此闭包在 <code v-pre>local</code> 环境中记录所有数据以及异常、失败的作业、计划任务和在所有其他环境中具有监视标记的数据：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isSlowQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="批处理" tabindex="-1"><a class="header-anchor" href="#批处理"><span>批处理</span></a></h3>
<p>虽然 <code v-pre>filter</code> 闭包用于过滤单个条目的数据，但你可以使用 <code v-pre>filterBatch</code> 方法来注册一个闭包，用于过滤给定请求或控制台命令的所有数据。如果闭包返回 <code v-pre>true</code>，则所有条目都将被 Telescope 记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Collection</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filterBatch</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Collection</span> <span class="token variable">$entries</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entries</span><span class="token operator">-></span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isSlowQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="标记" tabindex="-1"><a class="header-anchor" href="#标记"><span>标记</span></a></h2>
<p>Telescope 允许你通过「标记」搜索条目。通常，标记是 Eloquent 模型类名或经过身份验证的用户 ID，Telescope 会自动将其添加到条目中。偶尔，你可能希望将自定义标记附加到条目。为此，你可以使用 <code v-pre>Telescope::tag</code> 方法。<code v-pre>tag</code> 方法接受一个闭包，该闭包应返回一个标记数组。闭包返回的标记将与 Telescope 自动附加到条目的任何标记合并。通常情况下，你应该在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类的 <code v-pre>register</code> 方法中调用 <code v-pre>tag</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">tag</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">type</span> <span class="token operator">===</span> <span class="token string single-quoted-string">'request'</span></span>
<span class="line">                    <span class="token operator">?</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'status:'</span><span class="token operator">.</span><span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">content</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'response_status'</span><span class="token punctuation">]</span><span class="token punctuation">]</span></span>
<span class="line">                    <span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="可用观察者" tabindex="-1"><a class="header-anchor" href="#可用观察者"><span>可用观察者</span></a></h2>
<p>Telescope 的「观察者」在执行请求或控制台命令时收集应用程序数据。你可以在 <code v-pre>config/telescope.php</code> 配置文件中自定义要启用的观察者列表：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CacheWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>某些观察者还允许你提供额外的定制选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">100</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="批处理观察者" tabindex="-1"><a class="header-anchor" href="#批处理观察者"><span>批处理观察者</span></a></h3>
<p>批处理观察者记录有关排队的<a href="https://learnku.com/docs/laravel/11.x/queues#job-batching" target="_blank" rel="noopener noreferrer">批处理</a>的信息，包括作业和连接信息。</p>
<h3 id="缓存观察者" tabindex="-1"><a class="header-anchor" href="#缓存观察者"><span>缓存观察者</span></a></h3>
<p>缓存观察者在缓存键命中、未命中、更新和遗忘时记录数据。</p>
<h3 id="命令观察者" tabindex="-1"><a class="header-anchor" href="#命令观察者"><span>命令观察者</span></a></h3>
<p>命令观察者在执行 Artisan 命令时记录参数、选项、退出代码和输出。如果你希望排除某些命令被观察者记录，你可以在 <code v-pre>config/telescope.php</code> 文件中的 <code v-pre>ignore</code> 选项中指定这些命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_COMMAND_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'key:generate'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="dump-观察者" tabindex="-1"><a class="header-anchor" href="#dump-观察者"><span>Dump 观察者</span></a></h3>
<p>Dump 观察者记录并在 Telescope 中显示你的变量转储。在使用 Laravel 时，可以使用全局的 <code v-pre>dump</code> 函数转储变量。要记录转储，浏览器中必须打开 Dump 观察者选项卡，否则观察者将忽略转储。</p>
<h3 id="事件观察者" tabindex="-1"><a class="header-anchor" href="#事件观察者"><span>事件观察者</span></a></h3>
<p>事件观察者记录应用程序分派的任何<a href="https://learnku.com/docs/laravel/11.x/events" target="_blank" rel="noopener noreferrer">事件</a>的负载、侦听器和广播数据。 Laravel 框架内部事件将被事件观察者忽略。</p>
<h3 id="异常观察者" tabindex="-1"><a class="header-anchor" href="#异常观察者"><span>异常观察者</span></a></h3>
<p>异常观察者记录应用程序抛出的任何可报告异常的数据和堆栈跟踪。</p>
<h3 id="gate-观察者" tabindex="-1"><a class="header-anchor" href="#gate-观察者"><span>Gate 观察者</span></a></h3>
<p>Gate 观察者记录应用程序进行的<a href="https://learnku.com/docs/laravel/11.x/authorization" target="_blank" rel="noopener noreferrer">门禁和策略</a>检查的数据和结果。如果你希望排除观察者记录的某些权限，则可以在 <code v-pre>config/telescope.php</code> 文件中的 <code v-pre>ignore_abilities</code> 选项中指定这些权限：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>GateWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_GATE_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore_abilities'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'viewNova'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="http-客户端观察者" tabindex="-1"><a class="header-anchor" href="#http-客户端观察者"><span>HTTP 客户端观察者</span></a></h3>
<p>HTTP 客户端观察者记录应用程序发出的<a href="https://learnku.com/docs/laravel/11.x/http-client" target="_blank" rel="noopener noreferrer">HTTP 客户端请求</a>。</p>
<h3 id="作业观察者" tabindex="-1"><a class="header-anchor" href="#作业观察者"><span>作业观察者</span></a></h3>
<p>作业观察者记录应用程序分派的任何<a href="https://learnku.com/docs/laravel/11.x/queues" target="_blank" rel="noopener noreferrer">作业</a>的数据和状态。</p>
<h3 id="日志观察者" tabindex="-1"><a class="header-anchor" href="#日志观察者"><span>日志观察者</span></a></h3>
<p>日志观察者记录应用程序写入的<a href="https://learnku.com/docs/laravel/11.x/logging" target="_blank" rel="noopener noreferrer">日志数据</a>。默认情况下，Telescope 仅记录 <code v-pre>error</code> 级别及以上的日志。但是，你可以修改应用程序的 <code v-pre>config/telescope.php</code> 配置文件中的 <code v-pre>level</code> 选项来修改此行为：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>LogWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_LOG_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'level'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'debug'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="邮件观察者" tabindex="-1"><a class="header-anchor" href="#邮件观察者"><span>邮件观察者</span></a></h3>
<p>邮件观察者允许你在浏览器中预览应用程序发送的<a href="https://learnku.com/docs/laravel/11.x/mail" target="_blank" rel="noopener noreferrer">邮件</a>，以及它们的相关数据。你还可以将邮件下载为 <code v-pre>.eml</code> 文件。</p>
<h3 id="模型观察者" tabindex="-1"><a class="header-anchor" href="#模型观察者"><span>模型观察者</span></a></h3>
<h3 id="模型观察者-1" tabindex="-1"><a class="header-anchor" href="#模型观察者-1"><span>模型观察者</span></a></h3>
<p>模型观察者在调度 Eloquent <a href="https://learnku.com/docs/laravel/11.x/eloquent#events" target="_blank" rel="noopener noreferrer">模型事件</a> 时记录模型更改。你可以通过观察者的 <code v-pre>events</code> 选项指定应记录哪些模型事件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>ModelWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_MODEL_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'events'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'eloquent.created*'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'eloquent.updated*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你想记录在给定请求期间加载的模型数量，请启用 <code v-pre>hydrations</code> 选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>ModelWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_MODEL_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'events'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'eloquent.created*'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'eloquent.updated*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'hydrations'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="通知观察者" tabindex="-1"><a class="header-anchor" href="#通知观察者"><span>通知观察者</span></a></h3>
<p>通知观察者记录应用程序发送的所有<a href="https://learnku.com/docs/laravel/11.x/notifications" target="_blank" rel="noopener noreferrer">通知</a>。如果通知触发了邮件发送，并且你已启用邮件观察者，则邮件也可以在邮件观察者屏幕上预览。</p>
<h3 id="查询观察者" tabindex="-1"><a class="header-anchor" href="#查询观察者"><span>查询观察者</span></a></h3>
<p>查询观察者记录应用程序执行的所有查询的原始 SQL、绑定和执行时间。观察者还将任何执行时间超过 100 毫秒的查询标记为 <code v-pre>slow</code>。你可以使用观察者的 <code v-pre>slow</code> 选项自定义慢查询阈值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">50</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="redis-观察者" tabindex="-1"><a class="header-anchor" href="#redis-观察者"><span>Redis 观察者</span></a></h3>
<p>Redis 观察者记录应用程序执行的所有<a href="https://learnku.com/docs/laravel/11.x/redis" target="_blank" rel="noopener noreferrer">Redis</a>命令。如果你在使用 Redis 进行缓存，缓存命令也将被 Redis 观察者记录。</p>
<h3 id="请求观察者" tabindex="-1"><a class="header-anchor" href="#请求观察者"><span>请求观察者</span></a></h3>
<p>请求观察者记录应用程序处理的所有请求的请求、标头、会话和响应数据。你可以通过 <code v-pre>size_limit</code>（以千字节为单位）选项限制记录的响应数据大小：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>RequestWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_REQUEST_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'size_limit'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_RESPONSE_SIZE_LIMIT'</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="计划任务观察者" tabindex="-1"><a class="header-anchor" href="#计划任务观察者"><span>计划任务观察者</span></a></h3>
<p>计划任务观察者记录应用程序运行的任何<a href="https://learnku.com/docs/laravel/11.x/scheduling" target="_blank" rel="noopener noreferrer">定时任务</a>的命令和输出。</p>
<h3 id="视图观察者" tabindex="-1"><a class="header-anchor" href="#视图观察者"><span>视图观察者</span></a></h3>
<p>视图观察者记录渲染视图时使用的<a href="https://learnku.com/docs/laravel/11.x/views" target="_blank" rel="noopener noreferrer">视图</a>名称、路径、数据和&quot;组合器&quot;。</p>
<h2 id="显示用户头像" tabindex="-1"><a class="header-anchor" href="#显示用户头像"><span>显示用户头像</span></a></h2>
<p>Telescope 仪表板显示了在保存特定条目时进行身份验证的用户的头像。默认情况下，Telescope 将使用 Gravatar 网络服务来获取头像。但是，你可以通过在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类中注册回调来自定义头像 URL。回调函数将接收用户的 ID 和电子邮件地址，并应返回用户的头像图片 URL：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">avatar</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$id</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$email</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string single-quoted-string">'/avatars/'</span><span class="token operator">.</span><span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token property">avatar_path</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/telescopemd/16735" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/te...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/telescopemd/16735" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/te...</a></p>
</blockquote>
</div></template>


